package com.example.api.util;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 用于手动分类
 * 分页工具类
 * @author 老白
 */
@Data
public class OaPage implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 总记录数
     */
    private long totalCount;
    /**
     * 每页记录数
     */
    private long pageSize;
    /**
     * 总页数
     */
    private int totalPage;
    /**
     * 当前页数
     */
    private long pageIndex;
    /**
     * 列表数据
     */
    private List list;

    public OaPage(){
        this.list = new ArrayList();
    }

    public OaPage(List list, long totalCount, long pageIndex, long pageSize) {
        this.list = list;
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        this.pageIndex = pageIndex;
        this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
    }

    public OaPage(List list, Page page) {
        this.list = list;
        this.totalCount = page.getTotal();
        this.pageSize = page.getSize();
        this.pageIndex = page.getCurrent();
        this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
    }

    public OaPage(Page page) {
        this.list = page.getRecords();
        this.totalCount = page.getTotal();
        this.pageSize = page.getSize();
        this.pageIndex = page.getCurrent();
        this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
    }

}
